package com.sgb.member.ui.adapter

import android.content.Context
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.sgb.member.R
import com.sgb.member.databinding.MemberComJingYingItemBinding
import com.sgb.member.entity.AppIcon
import com.sgb.member.entity.MemberBusinessBean

class MemberJingYingListAdapter(
    val context: Context,
    var datas: List<MemberBusinessBean>,
    val back: (MemberBusinessBean) -> Unit
) :
    RecyclerView.Adapter<MemberJingYingListAdapter.ViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val binding: MemberComJingYingItemBinding = DataBindingUtil.inflate(
            LayoutInflater.from(parent.context),
            R.layout.member_com_jing_ying_item, parent, false
        );
        return ViewHolder(binding)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.binding.bean = datas[position]
        holder.binding.tvPrice.text = "￥${datas[position].price}/${datas[position].unit}"
        holder.binding.ll.setOnClickListener {
            back.invoke(datas[position])
        }
        holder.binding.executePendingBindings()
    }

    override fun getItemCount(): Int = datas.size

    inner class ViewHolder(val binding: MemberComJingYingItemBinding) :
        RecyclerView.ViewHolder(binding.getRoot())

}

